function startSocket() {}

startSocket.prototype.start = function(server) {
  const io = require("socket.io")(server);
  const fs = require("fs");
  io.of('/news').on("connection", socket => {
    socket.on("add user", data => {
      socket.emit("add user", data);
    });
    socket.on("send msg", data => {
      socket.broadcast.emit("new msg", data);
    });
    socket.on("send img", data => {
      var base64Data = data.img.replace(/^data:image\/\w+;base64,/, "");
      var dataBuffer = new Buffer(base64Data, "base64");
      var imgstr=data.dir+"/image" + Date.now() + ".png"
      fs.writeFile(
        "./public/img/"+imgstr,
        dataBuffer,
        function(err) {
          if (err) {
            console.warn(err);
          } else {
            data.img = "http://localhost:1123/img/" +imgstr;
          }
        }
      );
      socket.broadcast.emit("new img", data);
    });
  });
};
module.exports = startSocket;
